package nina.yiyou.attendance.s30pattern.output

import nina.yiyou.attendance.s30pattern.output.excel.OutXlsxWriter

import java.nio.file.Path
import java.util.stream.Collectors

class PatternXlsxExporter {

  PatternXlsxExporter(Path xlsxPath, List<String> keyList, List<Map> employeeList) {
    _xlsxPath = xlsxPath
    _keyList = keyList
    _employeeList = employeeList
  }

  void export() {
    def toLine = { Map line -> _keyList.collect { line[it] } }

    List<List> lineList = _employeeList.stream()
        .map { toLine(it) }
        .collect(Collectors.toList())

    new OutXlsxWriter(_xlsxPath, _keyList, lineList).write()
  }

  private final Path _xlsxPath

  private final List<String> _keyList
  private final List<Map> _employeeList
}
